package com.tianchi.lexiang.myinterface.impl;

import java.util.ArrayList;
import java.util.List;

import android.util.Log;

import com.tianchi.lexiang.myinterface.SearchInterface;

public class SearchManager {
	private static final String TAG = "SearchManager";
	private static SearchManager manager = new SearchManager();
	private List<SearchInterface> searchList = new ArrayList<SearchInterface>();
	private String firstSpell = "";
	
	public static SearchManager getSearchManager(){
		return manager;
	}
	
	public String getFirstSpell() {
		return firstSpell;
	}

	public void setFirstSpell(String firstSpell) {
		this.firstSpell = firstSpell;
	}

	public void addSearchClient(SearchInterface client){
		searchList.add(client);
	}
	
	public void deleteSearchClient(SearchInterface client){
		searchList.remove(client);
	}
	
	public void doSearchWork(){
		int size = searchList.size();
		Log.d(TAG, "[doSearchWork]size==>" + size);
		if (size > 1) {
			Log.e(TAG, "[doSearchWork] it's an error ,we should just have one client");
			return;
		}
		for (int i = 0; i < size; i++) {
			SearchInterface client = searchList.get(i);
			client.onSearch(firstSpell);
		}
	}
}
